package com.twobu.twobuinsight.common.errorcode;

/**
 * 通用错误码枚举
 */
public enum CommonErrorCode implements IErrorCode {

    // 成功
    SUCCESS(200, "操作成功"),

    // 客户端错误 4xx
    BAD_REQUEST(400, "请求参数错误"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法不允许"),
    REQUEST_TIMEOUT(408, "请求超时"),
    PARAM_VALIDATE_FAILED(412, "参数校验失败"),

    // 服务端错误 5xx
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),

    // 业务错误 6xx
    BUSINESS_ERROR(600, "业务处理异常"),
    DATA_ACCESS_ERROR(601, "数据访问异常"),
    DUPLICATE_KEY_ERROR(602, "数据已存在"),
    FOREIGN_KEY_ERROR(603, "数据关联异常"),
    DATA_INTEGRITY_ERROR(604, "数据完整性异常"),

    // 用户相关错误 7xx
    USER_NOT_FOUND(700, "用户不存在"),
    USER_ALREADY_EXISTS(701, "用户已存在"),
    PASSWORD_ERROR(702, "密码错误"),
    ACCOUNT_LOCKED(703, "账号已锁定"),
    LOGIN_EXPIRED(704, "登录已过期"),

    // 权限相关错误 8xx
    PERMISSION_DENIED(800, "权限不足"),
    ROLE_NOT_FOUND(801, "角色不存在"),

    // 文件相关错误 9xx
    FILE_NOT_FOUND(900, "文件不存在"),
    FILE_UPLOAD_ERROR(901, "文件上传失败"),
    FILE_SIZE_LIMIT(902, "文件大小超出限制"),
    FILE_TYPE_ERROR(903, "文件类型错误");

    private final Integer code;
    private final String message;

    CommonErrorCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer code() {
        return this.code;
    }

    @Override
    public String message() {
        return this.message;
    }
}
